package com.dongdong.controller;


import com.dongdong.service.BrandService;
import com.dongdong.utils.Result;
import com.dongdong.vo.BrandVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;


    @GetMapping("/getBrandList")
    public Result getBrandList() {
        List<BrandVO> brandVOS = brandService.getBrandList();
        return Result.OK().setData(brandVOS);
    }

    @PostMapping("/getBrandListLike")
    public Result getBrandListLike(@RequestBody BrandVO brandVO) {
        List<BrandVO> brandVOS = brandService.getBrandListLike(brandVO);
//        return new Result<>(ResultParam.SUCCESS_CODE,ResultParam.SUCCESS_MSG,brandVOS);
        return Result.OK().setData(brandVOS);
    }


    @PostMapping("/addBrand")
    public Result addBrand(@RequestBody BrandVO brandVO) {
        brandService.addBrand(brandVO);
        return Result.OK();
    }

    @GetMapping("/getBrandById")
    public Result getBrandById(@RequestParam Long bid){
        BrandVO brandVO = brandService.getBrandById(bid);
        return Result.OK().setData(brandVO);
    }

    @PutMapping("/updateBrand")
    public Result updateBrand(@RequestBody BrandVO brandVO) {
        brandService.updateBrand(brandVO);
        return Result.OK();
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam Long bid) {
        brandService.deleteById(bid);
        return Result.OK();
    }

    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestParam(name = "bids[]") List<Long> bids){
        brandService.deleteBatch(bids);
        return Result.OK();
    }
}
